package tech.ezrealc.fall2023.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import tech.ezrealc.fall2023.model.common.ResponseModel;
import tech.ezrealc.fall2023.model.user.UserDTO;
import tech.ezrealc.fall2023.model.user.UserVO;
import tech.ezrealc.fall2023.service.UserService;

@RestController
@RequestMapping("/api/user")
@CrossOrigin
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping
    public ResponseModel getUserInfo(@RequestHeader("Fall2023-Token") String token) {
        UserDTO userDTO = userService.getUserInfo(token);
        return ResponseModel.success(new UserVO(userDTO.getName(), userDTO.getEmail(), userDTO.getRole()));
    }

}
